﻿using System;
using System.Collections;
using System.Collections.Generic;
using GDGeek;
using Mirror;
using MrPP.Myth;
using UnityEngine;

namespace MrPP.SerriedCabinet
{
   
    public class Status  : NetworkBehaviour, IBridgeReceiver//, ICenterSystem
    {
        public enum Type{
            None,
            Check,
            Seach,
            Shelve,
        };

        public void Start() {
            BridgeBroadcast.Instance.addReceiver(this);
        }
        public void OnDestroy()
        {
            BridgeBroadcast.Instance.removeReceiver(this);
        }
        [SyncVar(hook="syncStatus")]
        private Type status_;

      //  private IStatus[] list;
        public Action<Type, Type> onStatus {
            get;
            set;
        }
        void syncStatus(Type oldValue, Type newValue)
        {
            onStatus?.Invoke(oldValue, newValue);
          
        }
     

        public string handle => this.longName();

        public void broadcast(string evt, object data)
        {
            switch (evt) {
                case "status_":
                    this.status_ = (Type)(int)(data);
                    break;
            }

        }

        public void change(Type status)
        {
            if (status == this.status_)
            {
                Bridge.Instance.post(this.handle, "status_", (int)Type.None);
            }
            else {
                Bridge.Instance.post(this.handle, "status_", (int)status);
            }
           

        }
        public void open(Type status)
        {

            Bridge.Instance.post(this.handle, "status_", (int)status);

        }
    }

}